<?php

namespace Cola;

use Suikachan\ExceptionHandlers\Render\DefaultRender;
use \Suikachan\ExceptionHandlers\Response\Response;

class ExceptionRender extends DefaultRender
{
    public function render(\Throwable $ex)
    {
        if(Request::isAjax())
        {
            $data = $this->getExceptionData($ex);
            return new class($data) implements Response {

                protected $data;

                public function __construct($data)
                {
                    $this->data = $data;
                }

                public function send()
                {
                    echo json_encode([
                        'message' => $this->data['message']
                    ]);
                }
            };
        }
        return parent::render($ex);
    }

}